package com.yuqing.sentimentapp.yqlist.presenter.impl;

import com.yuqing.sentimentapp.base.BaseObserver;
import com.yuqing.sentimentapp.module.ModuleManager;
import com.yuqing.sentimentapp.yqlist.fragment.YqListFragment;
import com.yuqing.sentimentapp.yqlist.bean.YqListResultBean;
import com.yuqing.sentimentapp.yqlist.presenter.YqListPresenter;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class YqListPresenterImpl implements YqListPresenter {

    private YqListFragment yqListFragment;

    public YqListPresenterImpl(YqListFragment yqListFragment) {
        this.yqListFragment = yqListFragment;
    }

    @Override
    public void loadYqListData(String phone, int page, int pageSize, boolean isRefresh) {
        ModuleManager.getInstance().loadYqListResult(yqListFragment.getContext(), phone, page, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<YqListResultBean>() {
                    @Override
                    protected void hideDialog() {
                        yqListFragment.stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        yqListFragment.startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(YqListResultBean yqListResultBean) {
                        yqListFragment.returnYqListResult(yqListResultBean, isRefresh);
                    }

                    @Override
                    protected void onFailure(String message) {
                        yqListFragment.onFailure(message);
                    }
                });
    }
}
